package com.zking.config;

import com.zking.interceptor.LoginInterceptor;
import com.zking.interceptor.ProjectInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {
   @Autowired
    private LoginInterceptor loginInterceptor;
    //重写配置拦截器的方法
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        //添加配置的拦截器的类
        registry.addInterceptor(loginInterceptor).addPathPatterns("/books","/books/*");
    }

    //设置静态资源访问过滤，当前类需要设置为配置类，并被扫描加载
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        //当访问/pages/????时候，从/pages目录下查找内容
        registry.addResourceHandler("/pages/**")
                .addResourceLocations("/pages/");
        registry.addResourceHandler("/js/**")
                .addResourceLocations("/js/");
        registry.addResourceHandler("/element-ui/**")
                .addResourceLocations("/element-ui/");
    }

}
